package org.linuxgears.BouncingBall;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

/**
 * Created by IntelliJ IDEA.
 * User: khilkeol
 * Date: 31 ���� 2010
 * Time: 8:08:48
 * To change this template use File | Settings | File Templates.
 */
public class BallFactory {

    public static final int DEFAULT_BALL_SIZE = 30;
    public static final Point DEFAULT_BALL_VELOCITY = new Point(2, 2);
    public static final Point IDLE_BALL_VELOCITY = new Point(0, 0);

    private static final Color[] BALL_COLORS = { Color.white, Color.green, Color.yellow, Color.orange, Color.red, Color.blue };
    private static int nextColorKey = 0;

    private static BallFactory instance = new BallFactory();

    private BallFactory() {

    }

    public static BallFactory getInstance() {
        return instance;
    }
    
    public Ball createColoredBall() {
        System.out.println("Creating new ball with color: " + BALL_COLORS[nextColorKey]);
        return new Ball((Point)BallFactory.DEFAULT_BALL_VELOCITY.clone(), BallFactory.DEFAULT_BALL_SIZE, getNextColor());
    }

    public static Color getNextColor() {
        nextColorKey = (nextColorKey + 1) % BALL_COLORS.length;
        return BALL_COLORS[nextColorKey];
    }

    public static Collection<Ball> getProductSet() {
        ArrayList<Ball> balls = new ArrayList<Ball>();
        for (int i = 0; i < BALL_COLORS.length; i++) {
            balls.add(BallFactory.getInstance().createColoredBall());
        }
        return balls;
    }

}
